
import java.util.LinkedList;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Carlos Magno
 */
public class MatriculaAluno extends javax.swing.JInternalFrame {

    /**
     * Creates new form MatriculaAluno
     */
    public MatriculaAluno(Aluno aluno, LinkedList<Disciplina> dics) {
        initComponents();
        this.aluno = aluno;
        labelAluno.setText(labelAluno.getText() + aluno.getNome());
        for (Disciplina d : dics) {
            cBoxDics.addItem(d.getNome());
        }
        cBoxDics.setSelectedIndex(-1);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cBoxDics = new javax.swing.JComboBox();
        botaoMat = new javax.swing.JButton();
        labelAluno = new javax.swing.JLabel();

        setClosable(true);
        setTitle("Matricular Aluno");

        labelDicCad.setText("Disciplinas Cadastradas:");

        botaoMat.setText("Matricular");
        botaoMat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMatActionPerformed(evt);
            }
        });

        labelAluno.setText("Aluno: ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelDicCad)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(cBoxDics, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(labelAluno)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 261, Short.MAX_VALUE)
                        .addComponent(botaoMat)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelDicCad)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cBoxDics, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoMat)
                    .addComponent(labelAluno))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoMatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoMatActionPerformed
        // TODO add your handling code here:
        disciplina = Caderneta.getDisciplinas().get(cBoxDics.getSelectedIndex());
        if (disciplina.getMatriculados().contains(aluno.getMatricula())) {
            JOptionPane.showMessageDialog(this, "O aluno já está matriculado nessa disciplina");
        } else {
            if (disciplina.getQtdeVagas() == disciplina.getQtdeMatriculados()) {
                JOptionPane.showMessageDialog(this, "Disciplina com capacidade máxima");
            } else {
                disciplina.getMatriculados().add(aluno.getMatricula());
                disciplina.getNotas().add(new double[disciplina.getQtdeNotas()]);
                disciplina.getSets().add(new boolean[disciplina.getQtdeNotas()]);
                disciplina.getFaltas().add(new int[]{0});
                disciplina.setQtdeMatriculados(disciplina.getQtdeMatriculados()+1);
                cBoxDics.setSelectedIndex(-1);
                JOptionPane.showMessageDialog(this, aluno.getNome() + " matriculado em " + disciplina.getNome());
            }
        }

    }//GEN-LAST:event_botaoMatActionPerformed
    Aluno aluno;
    Disciplina disciplina;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoMat;
    private javax.swing.JComboBox cBoxDics;
    private javax.swing.JLabel labelAluno;
    private final javax.swing.JLabel labelDicCad = new javax.swing.JLabel();
    // End of variables declaration//GEN-END:variables
}
